<template>
	<view class="wrap">
		<scroll-view scroll-y="true" class="left">
			<view :class="['item',{'active':currentIndex==index}]" v-for="(item,index) in leftContent" :key="index" @click="handleCheck(index)">
				{{item}}
			</view>
		</scroll-view>
		<scroll-view scroll-y="true" class="right">
			<view class="rightWrap" v-for="(item,index) in rightContent" :key="index">
				<view class="title">{{item.cat_name}}</view>
				<view class="main">
					<view class="itemShow" v-for="item1 in item.children" :key="item1.goods_id" @click="handleSendId(item1.goods_id)">
						<image :src="item1.cat_icon" mode="widthFix"></image>
						<text>{{item1.cat_name}}</text>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>
<script>
	import {categories} from "../../static/js/categories.js"
	export default {
		data() {
			return {
				leftContent:[],
				rightContent:[],
				currentIndex:0
			}
		},
		created() {
			this.leftContent = categories.map(v=>v.cat_name)
			this.rightContent = categories[this.currentIndex].children
			console.log(this.leftContent)
			console.log(this.rightContent)
		},
		methods: {
			handleCheck(index){
				this.currentIndex = index
				this.rightContent = categories[index].children
			},
			handleSendId(id){
				uni.navigateTo({
					url:"../detail/detail?goods_id=" + id
				})
			}
		}
	}
</script>

<style lang="less">
	page{height: 100%;}
	.wrap{
		display: flex;
		height: 100%;
		.left{
			flex: 2;
			background-color: #efefef;
			height: 100%;
			.item{
				line-height: 100rpx;
				display: flex;
				justify-content: center;
				align-items: center;
			}
			.active{
				border-right: 8rpx solid red;	
			}
		}
		.right{
			flex: 5;
			.rightWrap{
				width: 100%;
				padding: 30rpx;
				.title{
					font-weight: bold;
				}
				.main{
					width: 100%;
					display: flex;
					flex-wrap: wrap;
					
					.itemShow{
						width: 50%;
						image{
							width: 100%;
						}
					}
				}
			}
		}
	}
</style>
